package com.intel.two.listener.building;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.intel.two.bo.building.ResidentBo;
import com.intel.two.pojo.building.Resident;
import com.intel.two.service.building.ResidentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype") //多例模式
public class WebResidentBoListener extends AnalysisEventListener<ResidentBo> {
    @Autowired
    ResidentService residentService;

    @Override
    public void invoke(ResidentBo data, AnalysisContext context) {
        System.out.println("导入"+data);//这里的data不一致，拷贝属性
        Resident resident = new Resident();
        BeanUtils.copyProperties(data,resident);

        //每读一行数据，就添加一次
        residentService.addResident(resident);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
